<?php
	require_once 'Connect.class.php';
	require_once 'DanhMuc.class.php';
	/**
	* 
	*/
	class ChuyenNganh extends DanhMuc
	{
		
		public function __construct()
		{
			# code...
		}
		public function getInfo($maCN){

			$conn= new Connect();

			$conn->Query("SELECT * FROM tbl_chuyen_nganh WHERE maCN='".$maCN."'; ");	

			while ($row=$conn->Fetch()) {	

				$this->ma=$row['maCN'];
				
				$this->ten=$row['tenCN'];
			}
			// dong ket noi
			$conn->close();
		}

		public function ds()
		{
			$ds=array();
			$conn= new Connect();
			$conn->Query("SELECT * FROM tbl_chuyen_nganh");
			$index=0;
			while ($row=$conn->Fetch()) {
				$cn= new ChuyenNganh();
				$cn->setMa($row['maCN']);
				$cn->setTen($row['tenCN']);
				$ds[$index]=$cn;
				$index++;
			}
			$conn->close();
			return $ds;
		}
		public function them(){

			$sql="INSERT INTO tbl_chuyen_nganh(maCN,tenCN) values('".$this->ma."','".$this->ten."')";

			$conn=new Connect();

			$conn->Query($sql);

			$conn->close();
			
		}
		public function checkNo($maCN){

			$rs=false;

			$conn= new Connect();

			$conn->Query("SELECT COUNT(maCN) as dem FROM tbl_chuyen_nganh WHERE maCN='".$maCN."'; ");	

			while ($row=$conn->Fetch()) {	
				if ($row['dem']==1){
					$rs=true;
				}
			}
			// dong ket noi
			$conn->close();
			return $rs;
		}
	
		public function xoa(){
			$sql="DELETE FROM tbl_chuyen_nganh WHERE maCN='".$this->ma."'";

			$conn=new Connect();

			$conn->Query($sql);

			$conn->close();

		}
		public function capnhat(){
			$sql="UPDATE tbl_chuyen_nganh SET tenCN='".$this->ten."' WHERE maCN='".$this->ma."'";

			$conn=new Connect();

			$conn->Query($sql);

			$conn->close();
		}

	}
?>